package com.smh.imagesearchmcpserver;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;

@RestController
public class ImageSearchSseController {
    @GetMapping(value = "/sse/test", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter sseTest() throws IOException {
        SseEmitter emitter = new SseEmitter();
        String apiKey = ApiKeyContext.getApiKey();
        try {
            emitter.send(SseEmitter.event().name("message").data("你的API KEY是: " + apiKey));
            emitter.complete();
        } catch (IOException e) {
            emitter.completeWithError(e);
        }
        return emitter;
    }
}